var template = require('../../../../template/backstageTemplate.js');
var t = function (t) {
    return t && t.__esModule ? t : {
      default: t
    };
  }(),
  app = getApp(),
  e = 0;
var page = 1;
Page({
  data: {
    curHdIndex: 1,
    type: '0',
    index: 5,
    page: 0,
    pagesize: 10,
    list: [],
    pageOne: 0,
    pageTwo: 0,
    prenumber: 20,
    tsid: 1,
    loadingBoo: !0,
    moreBooOne: !0,
    moreBooTwo: !0,
    communityListOne: [],
    communityListTwo: [],
    url: "patient/community/list/",
    oneBoo: !1,
    twoBoo: !1,
    mask: !0,
    currindex: 0,
    itemList: [],
    ismore: true,
    teamitem: ['我创建的', '我加入的'],
    teamindex: 0,
    myfound: [{}, {}, {}],
    myadd: [{}, {}],
    keyword: "",
  },
  teamindex: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid;
    var zids = wx.getStorageSync('zid');
    if (zids == zid) {
      wx.navigateTo({
        url: '/hyb_yl/backstageTeam/pages/teamDetails/teamDetails?id=' + id,
      })
    } else {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/teamcenters/teamcenters?id=' + id,
      })
    }

  },
  // 同意加入团队
  agree: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    wx.showModal({
      title: '提示',
      content: "确认加入该团队吗？",
      success: function (con) {
        if (con.confirm) {
          app.util.request({
            'url': "entry/wxapp/zhuanjia.addteam",
            data: {
              zid: wx.getStorageSync('zid'),
              id: id,
              status: status
            },
            success: function (res) {
              wx.showToast({
                title: '加入成功',
              })
              that.setData({
                page: 0,
                list: []
              })
              wx.setTimeout(() => {
                that.getList(that.data.type, that.data.keyword)
              }, 500);
            }
          })
        }
      }
    })
  },

  teamtab: function (e) {
    const index = e.currentTarget.dataset.dex;
    this.setData({
      type: index,
      page: 0,
      list: []
    })
    this.getList(index, this.data.keyword)
  },
  createteam: function () {
    wx.navigateTo({
      url: '/hyb_yl/backstageTeam/pages/createTeam/createTeam',
    })
  },
  onLoad: function (t) {
    template.tabbar("tabBar", 1, this);
    var a = this;
    var bgc = wx.getStorageSync('color')
    a.setData({
      bgc: bgc
    })
    page = 1;
    a.getAllshare(page);
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    
  },
  getList: function (type, keyword) {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.teamlists",
      data: {
        zid: wx.getStorageSync('zid'),
        page: that.data.page,
        pagesize: that.data.pagesize,
        type: type,
        keyword: keyword
      },
      success: function (res) {
        var page = that.data.page + 1;
        that.setData({
          page: page,
          list: that.data.list.concat(res.data)
        })
      }
    })
  },
  changes: function (e) {
    var keyword = e.detail.value;
    this.setData({
      keyword: keyword
    })
  },
  searchs: function () {
    var that = this;
    var type = that.data.type;
    var keyword = that.data.keyword;
    that.setData({
      page: 0,
      list: []
    })
    that.getList(type, keyword)
  },
  onReady: function () {},
  onShow: function () {
    var that = this;
    that.setData({
      page:0,
      list:[]
    })
    that.getList(0, '');
  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {
    var type = this.data.type;
    var keyword = this.data.keyword;
    this.getList(type, keyword)
  },
  onShareAppMessage: function () {},
  //发表动态
  addCommunity: function () {
    wx.navigateTo({
      url: "/hyb_yl/userLife/pages/addDynamic/addDynamic"
    });
  },

  //查询所有分享
  getAllshare: function (_page) {
    var that = this
    app.util.request({
      url: 'entry/wxapp/share.allshare',
      data: {
        openid: wx.getStorageSync('openid'),
        page: _page,
        pagback: 5,
        state: 1
      },
      success: function (res) {
        console.log(res)
        if (res.data.length < 5) {
          that.setData({
            ismore: false
          })
        }
        var list_t = that.data.itemList;
        console.log(list_t)
        var len = res.data.length;
        for (var i = 0; i < len; i++) {
          list_t.push(res.data[i])
        }
        wx.hideLoading()
        that.setData({
          communityListOne: list_t,
          page: 1,
        })
      }
    })
  },
  previewImage: function (a) {
    var t = this;
    console.log(a)
    var i = a.currentTarget.dataset.index;
    var url = a.currentTarget.dataset.url
    var artrs = a.currentTarget.dataset.data
    console.log(i, url, artrs)
    wx.previewImage({
      current: url,
      urls: artrs
    });
  },
  scrolltolower() {
    var that = this
    console.log(that.data.ismore)
    if (that.data.ismore) {
      page++;
      console.log(page)
      that.getAllshare(page);
    }
  },
});